package com.imau.controller;

import com.imau.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "userCheckNameServlet", value = "/userCheckNameServlet")
public class UserCheckNameServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");

        System.out.println("检查用户名");
        String userName = request.getParameter("userName");
        if (userService.checkUserName(userName)) {
            response.getWriter().write("true");
        } else {
            response.getWriter().write("false");
        }

    }
}
